<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>js数据类型</title>
</head>
<body>
<script type="text/javascript">
    var dd = "全局变量";

    var test = {
        dd: "test的属性",
        ff: "John",
        aa: dd,
        ee: this,  //this 是 全局对象
        cc: {
            yy: "test.cc的属性",
            tt: function () {
                console.log(this);//this 是 test.cc
            }
        },
        bb: function () {
            console.log(this)//this 是 test
        }
    };

    test.cc.tt();
    test.bb();
    console.log( test.ee)

    //添加新属性的方法
    test.param = "添加新属性的方法";
    //添加新属性的方法
    test["tttt"] = "第二种添加新属性的方法";

    var teacher = {
        teachernn: "teachernn的属性",

        student: {
            studentnn: "student的属性",

            tt: function (param) {

                console.log(param.name);
                console.log(this);//this 是 student
            }
        },

        kk: function () {
            this.student.tt({name: this});//this 是 teacher   所以这里的this 是无法指向自己的,只能是外部类teacher
        }
    };
    teacher.kk();


</script>
</body>
</html>










